<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;
class WeixinhuifuController extends AdminbaseController{
	

	
	function _initialize() {
		parent::_initialize();
		$this->db = D("WeixinHuifu");



		C("DEFAULT_FILTER","trim");
	}
	
	function index(){


		$keyword=I("get.keyword");

		$search=false;
		if($keyword){


			$where['name']  = array('like', '%'.$keyword.'%');
			$where['key']  = array('like','%'.$keyword.'%');
			$where['_logic'] = 'or';
			$map['_complex'] = $where;



			$search=true;
			$this->assign("keyword",$keyword);
		}





		$this->assign("search",$search);

		$count=$this->db->where($map)->count();
		$page = $this->page($count);
		$list=$this->db->limit($page->firstRow . ',' . $page->listRows)->order ( "id desc ")->where($map)->select();




		$this->assign("Page",$page->show(""));

		$this->assign("_list",$list);

		$this->display();




	}
	


	function add(){
		
		if(IS_POST){




			$_POST["key"]=",".$_POST["key"].",";





			
			if ($this->db->create($_POST)) {
				if ($this->db->add()!==false) {
					$this->success("添加成功！", U("index"));
				} else {
					$this->error("添加失败！");
				}
			} else {
				$this->error($this->db->getError());
			}
		}else{


			$type= I("get.type")?I("get.type"):"wenzi";


			
			

		$this->display("add_".$type);
		}
		}
	
	
	function edit(){
		
		
		if(IS_POST){

			$_POST["key"]=",".$_POST["key"].",";
			
			if ($this->db->create($_POST)) {
				
				if ($this->db->save()!==false) {
					$this->success("保存成功！", U("index"));
				} else {
					$this->error("保存失败！");
				}
			} else {
				$this->error($this->db->getError());
			}

		} else {

			$id = intval(I("get.id"));
			if (!$id) {
				$this->error("缺少参数！");
			}


			$r = $this->db->where("id=$id")->find();



			$this->assign("data", $r);






			$this->display("edit_".$r["type"]);



		}
	}
	

	
	

	function delete(){
		$id = intval(I("get.id"));



		if ($this->db->delete($id)) {


			$this->success("删除成功！");
		} else {
			$this->error("删除失败！");
		}
	}
	

	
	


	
	}
